//
//  HBPageSegmentDemoViewController.m
//  HBLibary_Example
//
//  Created by Rambo on 2018/8/20.
//  Copyright © 2018年 Rambo. All rights reserved.
//

#import "HBPageSegmentDemoViewController.h"


@interface HBPageSegmentDemoViewController ()

@end

@implementation HBPageSegmentDemoViewController



- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.view.backgroundColor = [UIColor whiteColor];
    
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    [button setTitle:@"跳转到分段控制器" forState:UIControlStateNormal];
    button.backgroundColor = [UIColor redColor];
    button.frame = CGRectMake(0, 0, 200, 44);
    [button addTarget:self action:@selector(jumpPageSegmentVC) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:button];
    button.center = self.view.center;
}


- (void)jumpPageSegmentVC{
    
    NSMutableArray *titles = [NSMutableArray array];
    NSMutableArray *viewControllers = [NSMutableArray array];
    
    for (NSInteger index = 0; index < 3; index++) {
        NSString *title = [NSString stringWithFormat:@"分段%zd",index];
        [titles addObject:title];
        
        UIViewController *vc = [[UIViewController alloc] init];
        vc.view.backgroundColor = [UIColor colorWithRed:(arc4random()%255)/255.0f green:(arc4random()%255)/255.0f blue:(arc4random()%255)/255.0f alpha:1.0f];
        [viewControllers addObject:vc];
    }
    
//    HBPageSegmentViewController *vc = [[HBPageSegmentViewController alloc] initWithPageSegmentTitleFont:[UIFont systemFontOfSize:16] titles:titles viewControllers:viewControllers minMargin:0 defaultSelectIndex:0];
    
    HBPageSegmentViewController *vc = [[HBPageSegmentViewController alloc] initWithPageSegmentTitleFont:[UIFont systemFontOfSize:16] titles:titles viewControllers:viewControllers minMargin:0 tagWidth:([UIScreen mainScreen].bounds.size.width / titles.count) defaultSelectIndex:0];
    
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        [vc.pageSegmentView updateTitle:@"段子" atIndex:1];
    });
    
    
//    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
//        [vc.pageSegmentView updateTitle:@"测试改变" atIndex:2];
//    });
    
//    vc.pageSegmentView.selectLineWidth = 20;
    vc.pageSegmentView.selectLineHeight = 4;
    vc.pageSegmentView.selectLineJoinType = HBPageSegmentViewSelectLineJoinTypeRound;
    [self.navigationController pushViewController:vc animated:YES];
    
}

@end
